/*
**********************************************************************************
 ECE 527 Project 3
 Module: ling4_adder
 Description: Implementation of 4 bit Ling's adder 

 Team : Rohit Kulkarni
        Akshay Kotian
**********************************************************************************
*/

module ling4(sum,Cout,a,b,Cin);                                                                               
output reg [3:0] sum;                          
output reg Cout;                           
input [3:0] a;                         
input [3:0] b;                          
input Cin;                                                                                                           
reg [3:-1] t;
reg [3:0] g;
reg [4:1] h;  

always @(*)
begin    

  t[-1]= 1'b1;						//Set t[-] =1 to read Cin from previous block
  g[3:0]=a[3:0] & b[3:0];          
  t[3:0]=a[3:0] | b[3:0];                                                                               
  h[1]=g[0] | (Cin&t[-1]);            
  h[2]=g[1] | g[0] | (t[0]&Cin);
  h[3]=g[2] | g[1] | (g[0]&t[1]) | (t[0]&t[1]&Cin);
  h[4]=g[3] | g[2] | (g[1]&t[2]) | (g[0]&t[1]&t[2]) | (t[0]&t[1]&t[2]&Cin);  
  Cout=h[4] & t[3];                                                                                      
  sum[0]=(t[0] ^ h[1]) | (Cin & t[0] & g[0]); 
  sum[3:1]=(t[3:1] ^ h[4:2]) | (h[3:1] & t[2:0] & g[3:1]);
end
endmodule     
